/**
 * AI音乐创作API接口 (基于ai_music模块)
 */
import api from '@/utils/api'

export const musicApi = {
  // 音乐创作
  compose: {
    // 创建音乐创作任务
    create: (compositionData) => api.post('/ai-music/compose/', compositionData),
    
    // 获取创作任务状态
    getStatus: (taskId) => api.get(`/ai-music/compose/${taskId}/status/`),
    
    // 取消创作任务
    cancel: (taskId) => api.post(`/ai-music/compose/${taskId}/cancel/`),
    
    // 续写音乐
    continue: (compositionId, continueData) => api.post(`/ai-music/compositions/${compositionId}/continue/`, continueData),
  },

  // 音乐作品管理
  compositions: {
    // 获取作品列表
    getList: (params = {}) => api.get('/ai-music/compositions/', { params }),
    
    // 获取作品详情
    getDetail: (compositionId) => api.get(`/ai-music/compositions/${compositionId}/`),
    
    // 更新作品信息
    update: (compositionId, compositionData) => api.put(`/ai-music/compositions/${compositionId}/`, compositionData),
    
    // 删除作品
    delete: (compositionId) => api.delete(`/ai-music/compositions/${compositionId}/`),
    
    // 下载音频文件
    downloadAudio: (compositionId, format = 'mp3') => api.get(`/ai-music/compositions/${compositionId}/download/audio/`, {
      params: { format },
      responseType: 'blob'
    }),
    
    // 下载MIDI文件
    downloadMIDI: (compositionId) => api.get(`/ai-music/compositions/${compositionId}/download/midi/`, {
      responseType: 'blob'
    }),
  },

  // 音乐编辑
  edit: {
    // 编辑音乐结构
    editStructure: (compositionId, structureData) => api.post(`/ai-music/compositions/${compositionId}/edit-structure/`, structureData),
    
    // 调整乐器配置
    editInstruments: (compositionId, instrumentData) => api.post(`/ai-music/compositions/${compositionId}/edit-instruments/`, instrumentData),
    
    // 调整音乐参数
    editParameters: (compositionId, parameters) => api.post(`/ai-music/compositions/${compositionId}/edit-parameters/`, parameters),
    
    // 生成变奏
    generateVariation: (compositionId, variationData) => api.post(`/ai-music/compositions/${compositionId}/variation/`, variationData),
  },

  // 音乐风格和模板
  styles: {
    // 获取音乐风格列表
    getList: () => api.get('/ai-music/styles/'),
    
    // 获取风格详情
    getDetail: (styleId) => api.get(`/ai-music/styles/${styleId}/`),
    
    // 获取风格示例
    getExamples: (styleId) => api.get(`/ai-music/styles/${styleId}/examples/`),
  },

  // 乐器配置
  instruments: {
    // 获取可用乐器列表
    getList: () => api.get('/ai-music/instruments/'),
    
    // 获取乐器详情
    getDetail: (instrumentId) => api.get(`/ai-music/instruments/${instrumentId}/`),
    
    // 获取乐器组合建议
    getSuggestions: (style) => api.get('/ai-music/instruments/suggestions/', { params: { style } }),
  },

  // 音频渲染
  render: {
    // 渲染音频
    renderAudio: (compositionId, renderOptions) => api.post(`/ai-music/compositions/${compositionId}/render/`, renderOptions),
    
    // 获取渲染状态
    getRenderStatus: (renderId) => api.get(`/ai-music/render/${renderId}/status/`),
    
    // 预览音频
    preview: (compositionId, previewOptions) => api.post(`/ai-music/compositions/${compositionId}/preview/`, previewOptions),
  },

  // 音乐分析
  analyze: {
    // 分析音乐结构
    analyzeStructure: (compositionId) => api.post(`/ai-music/compositions/${compositionId}/analyze-structure/`),
    
    // 分析和声
    analyzeHarmony: (compositionId) => api.post(`/ai-music/compositions/${compositionId}/analyze-harmony/`),
    
    // 分析节奏
    analyzeRhythm: (compositionId) => api.post(`/ai-music/compositions/${compositionId}/analyze-rhythm/`),
    
    // 获取音乐统计
    getStats: (compositionId) => api.get(`/ai-music/compositions/${compositionId}/stats/`),
  },

  // 模板管理
  templates: {
    // 获取模板列表
    getList: (params = {}) => api.get('/ai-music/templates/', { params }),
    
    // 获取模板详情
    getDetail: (templateId) => api.get(`/ai-music/templates/${templateId}/`),
    
    // 从模板创建音乐
    createFromTemplate: (templateId, customData) => api.post(`/ai-music/templates/${templateId}/create/`, customData),
  },

  // 音乐库
  library: {
    // 获取用户音乐库
    getLibrary: (params = {}) => api.get('/ai-music/library/', { params }),
    
    // 添加到音乐库
    addToLibrary: (compositionId) => api.post(`/ai-music/compositions/${compositionId}/add-to-library/`),
    
    // 从音乐库移除
    removeFromLibrary: (compositionId) => api.delete(`/ai-music/compositions/${compositionId}/remove-from-library/`),
  },

  // 分享和协作
  share: {
    // 创建分享链接
    createLink: (compositionId, shareData) => api.post(`/ai-music/compositions/${compositionId}/share/`, shareData),
    
    // 获取分享信息
    getInfo: (shareId) => api.get(`/ai-music/share/${shareId}/`),
    
    // 协作邀请
    invite: (compositionId, inviteData) => api.post(`/ai-music/compositions/${compositionId}/invite/`, inviteData),
  },

  // AI引擎管理
  engines: {
    // 获取可用AI引擎
    getList: () => api.get('/ai-music/engines/'),
    
    // 获取引擎能力
    getCapabilities: (engineId) => api.get(`/ai-music/engines/${engineId}/capabilities/`),
  }
}

export default musicApi